package se.webbzon.boltzmann.menu;

import java.awt.image.ImageObserver;

import se.webbzon.boltzmann.configuration.Graphics;
import se.webbzon.boltzmann.configuration.Graphics.*;

public class ResolutionPage extends MFlowPage {

	/*============================================================
	Constructors
	============================================================*/
	
	public ResolutionPage(ImageObserver observer, AbstractGameMenuLayout layout, MPage parent) {
		super(observer,layout.getPageLayout(),parent,"Resolution");
		ResolutionGroup group = new ResolutionGroup();
		
		addItem(new PageLabel(observer, layout.getLabelLayout(),this));
		addRow(0.25);
		addItem(new ReturnButton(observer,layout.getButtonLayout(), parent));
		addRow();
		addItem(new ApplyButton(layout.getButtonLayout(),group));
		addRow();
		addItem(new LowRadio(layout.getButtonLayout(),group));
		addRow(0.25);
		addItem(new MediumRadio(layout.getButtonLayout(),group));
		addRow(0.25);
		addItem(new HighRadio(layout.getButtonLayout(),group));
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override public void onEnter(GameMenu menu) {}

	@Override public void onLeave(GameMenu menu) {}
	
	/*============================================================
	Private Classes
	============================================================*/
	
	private final class ApplyButton extends MButton {
		
		private final ResolutionGroup group;

		public ApplyButton(ButtonLayout layout, ResolutionGroup group) {
			super(getImageObserver(), layout, false, "Apply");
			this.group = group;
		}

		@Override public void onClick(GameMenu menu) {
			Graphics.instance().setResolution((Resolution) group.getValue());
		}
		
	}
	
	private final class ResolutionGroup extends MRadioGroup {

		public ResolutionGroup() {
			super(Graphics.instance().getResolution());
		}

		@Override public void onChangeValue(Object value) {};

	}
	
	private final class LowRadio extends MRadio {

		public LowRadio(ButtonLayout layout, ResolutionGroup group) {
			super(getImageObserver(), layout, group, Resolution.LOW ,false, "Low (360p)");
		}
		
	}
	
	private final class MediumRadio extends MRadio {

		public MediumRadio(ButtonLayout layout, ResolutionGroup group) {
			super(getImageObserver(), layout, group, Resolution.MEDIUM ,false, "Medium (540p)");
		}
		
	}
	
	private final class HighRadio extends MRadio {

		public HighRadio(ButtonLayout layout, ResolutionGroup group) {
			super(getImageObserver(), layout, group, Resolution.HIGH ,false, "High (720p)");
		}
		
	}

}
